package bb.lanxing.network;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import okhttp3.Request;
import okhttp3.ResponseBody;

public abstract class AbsResponse implements Response {
    protected final Map<String, Object> params;

    private AbsResponse(Map<String, Object> map) {
        this.params = map;
    }

    @Override
    public Map<String, Object> getParams() {
        return this.params;
    }

    @Override
    public Object getParam(String str) {
        return this.params.get(str);
    }

    public static class Builder {
        private Map<String, Object> params = new HashMap();
        private okhttp3.Response response;

        public Builder() {
        }

        public Builder(okhttp3.Response response) {
            this.response = response;
        }

        public Builder append(String str, Object obj) {
            this.params.put(str, obj);
            return this;
        }

        public Builder appendAll(Map<String, Object> map) {
            this.params.putAll(map);
            return this;
        }

        public Builder response(okhttp3.Response response) {
            this.response = response;
            return this;
        }

        public Response build() {
            return new ResponseImpl(this.response, this.params);
        }

        public Response buildEmpty() {
            return new EmptyResponse(this.params);
        }
    }

    public static class ResponseImpl extends AbsResponse {
        private final okhttp3.Response response;

        private ResponseImpl(okhttp3.Response response, Map<String, Object> map) {
            super(map);
            this.response = response;
        }

        @Override
        public okhttp3.Response getResponse() {
            return this.response;
        }

        @Override
        public String getBodyString() throws IOException {
            ResponseBody body;
            okhttp3.Response response = this.response;
            if (response == null || (body = response.body()) == null) {
                return null;
            }
            return body.string();
        }

        @Override
        public Request getRequest() {
            return this.response.request();
        }
    }

    public static class EmptyResponse extends AbsResponse {
        private EmptyResponse(Map<String, Object> map) {
            super(map);
        }

        @Override
        public Request getRequest() {
            throw new IllegalAccessError("method not implement !");
        }

        @Override
        public okhttp3.Response getResponse() {
            throw new IllegalAccessError("method not implement !");
        }

        @Override
        public String getBodyString() throws IOException {
            throw new IllegalAccessError("method not implement !");
        }
    }
}
